<template>
    <!-- 日期选择器 -->
    <view class="example-body">
        <uni-datetime-picker type="datetime" v-model="sellTime" @change="getDataTime" />
    </view>
</template>

<script>
    import {
        mapState,
        mapMutations,
        mapGetters
    } from 'vuex'

    export default {
        name: "dataChage",
        data() {
            return {};
        },
        computed: {
            ...mapState('sellOrderStore', ['sellTime']),
        },
        methods: {
            ...mapMutations('sellOrderStore', ['updataSellTime']),
            //获取时间
            getDataTime(e) {
                this.updataSellTime(e)
            },
            //获取当前时间
            getDateTime(date, addZero = true) {
                return `${this.getDate(date, addZero)} ${this.getTime(date, addZero)}`
            },
            getDate(date, addZero = true) {
                date = new Date(date)
                const year = date.getFullYear()
                const month = date.getMonth() + 1
                const day = date.getDate()
                return `${year}-${addZero ? this.addZero(month) : month}-${addZero ? this.addZero(day) : day}`
            },
            getTime(date, addZero = true) {
                date = new Date(date)
                const hour = date.getHours()
                const minute = date.getMinutes()
                const second = date.getSeconds()
                return this.hideSecond ?
                    `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}` :
                    `${addZero ? this.addZero(hour) : hour}:${addZero ? this.addZero(minute) : minute}:${addZero ? this.addZero(second) : second}`
            },
            addZero(num) {
                if (num < 10) {
                    num = `0${num}`
                }
                return num
            }
        }
    }
</script>

<style lang="scss">
    .example-body {
        background-color: #fff;
        margin-top: 3px;
    }
</style>